package com.guochu.utils;

import java.util.List;
import java.util.Map;

/**
 * Map工具类，继承org.apache.commons.collections.MapUtils类
 *
 * @author bunting.wei
 * @since 2020-12-11 09:19:40
 */
public class MapUtils extends org.apache.commons.collections.MapUtils {

    /**
     * 取List值
     *
     * @param map
     * @param key
     * @param <T>
     * @return
     */
    public static <T> List<T> getList(Map map, Object key) {
        if (map != null) {
            Object answer = map.get(key);
            if (answer != null) {
                return (List<T>) answer;
            }
        }
        return null;
    }

    /**
     * 取List值，为null取默认值
     *
     * @param map
     * @param key
     * @param defaultValue
     * @param <T>
     * @return
     */
    public static <T> List<T> getList(Map map, Object key, List<T> defaultValue) {
        if (map != null) {
            Object answer = map.get(key);
            if (answer != null) {
                return (List<T>) answer;
            }
        }
        return defaultValue;
    }

}
